use local_ip_address::local_ip;
use serde::{Deserialize, Serialize};
use crate::features::system::{get_total_memory, get_used_memory};

#[derive(Serialize, Deserialize)]
pub struct Instance {
    pub id: i64,
    ip: String,
    status: Status,
    total_memory: u64,
    used_memory: u64
}

#[derive(Serialize, Deserialize)]
pub enum Status {
    Normal,
    Online
}

impl Instance {
    pub fn new() -> Instance {
        Instance {
            id: 0,
            ip: local_ip().unwrap().to_string(),
            status: Status::Normal,
            total_memory: get_total_memory(),
            used_memory: get_used_memory()
        }
    }

    pub fn set_id(&mut self, id: i64) {
        self.id = id;
    }

    pub fn set_status(&mut self, status: Status) {
        self.status = status;
    }
}